

import { Button, Space } from 'antd';
import { history, useModel }  from 'umi';

const HomePage=()=> {
   const { setInitialState, initialState } =
      useModel('@@initialState');
  const handleLogOut = () =>{
    localStorage.removeItem('token');
    setInitialState({...initialState,currentUser: null} as any);
    history.replace('/login')
  }
  const changeRole = (newRole:string) =>{
     const newToken = `role_${newRole}_token`;
    localStorage.setItem('token', newToken); // 存储新角色 token
    window.location.reload();
  }
  return (
    <div className='container'>
     <Space>
       <Button onClick={handleLogOut} type='default'>退出登录</Button>
       <Button onClick={()=>changeRole('user')} type='primary'>切换user角色</Button>
       <Button onClick={()=>changeRole('admin')} type='primary'>切换Admin角色</Button>
     </Space>
    </div>
  );
}
export default HomePage;